var datas=[];
function alltypepageing(url,sear) {
    var adata = {
        name : sear,
        pagesize : 999,
        pagenumber : 1
    };
    $.ajax({
        type : "GET",
        data : adata,
        dataType : "json",
        url : url,
        success : function(json) {
            datas = json.records;
            var bloodSugar = [],jdmxzl=[],bmi=[],drink=[0,0,0,0,0];
            for (var i=0;i<datas.length;i++){
                bloodSugar[i]=[datas[i].drink,datas[i].bloodSugar];
                jdmxzl[i]=[datas[i].drink,datas[i].jdmxzl];
                bmi[i]=[datas[i].drink,datas[i].bmi];
                if (datas[i].drink<"250"){
                    drink[0]+=1;
                } else if (datas[i].drink<"500") {
                    drink[1]+=1;
                } else if (datas[i].drink<"750") {
                    drink[2]+=1;
                } else if (datas[i].drink<"1000") {
                    drink[3]+=1;
                } else {
                    drink[4]+=1;
                }
            }


            var dom = document.getElementById("container");
            var myChart = echarts.init(dom);
            var myRegression = ecStat.regression('polynomial', bloodSugar, 3);
            myRegression.points.sort(function(a, b) {
                return a[0] - b[0];
            });
            option = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross'
                    }
                },
                title: {
                    text: '喝酒指数与血糖折线图',
                    left: 'center',
                    top: 16
                },
                xAxis: {
                    type: 'value',
                    splitLine: {
                        lineStyle: {
                            type: 'dashed'
                        }
                    },
                    splitNumber: 20
                },
                yAxis: {
                    type: 'value',
                    min: 0,
                    splitLine: {
                        lineStyle: {
                            type: 'dashed'
                        }
                    }
                },
                grid: {
                    top: 90
                },
                series: [{
                    name: '喝酒指数与血糖水平',
                    type: 'scatter',
                    label: {
                        emphasis: {
                            show: true,
                            position: 'right',
                            textStyle: {
                                color: 'blue',
                                fontSize: 16
                            }
                        }
                    },
                    data: bloodSugar
                }, {
                    name: 'line',
                    type: 'line',
                    smooth: true,
                    showSymbol: false,
                    data: myRegression.points,
                    markPoint: {
                        itemStyle: {
                            normal: {
                                color: 'transparent'
                            }
                        },
                        label: {
                            normal: {
                                show: true,
                                position: 'left',
                                formatter: myRegression.expression,
                                textStyle: {
                                    color: '#333',
                                    fontSize: 14
                                }
                            }
                        },
                        data: [{
                            coord: myRegression.points[myRegression.points.length - 1]
                        }]
                    }
                }]
            };
            myChart.setOption(option);

            var dom2 = document.getElementById("container2");
            var myChart2 = echarts.init(dom2);
            var myRegression2 = ecStat.regression('polynomial', jdmxzl, 3);
            myRegression2.points.sort(function(a, b) {
                return a[0] - b[0];
            });
            option2 = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross'
                    }
                },
                title: {
                    text: '喝酒指数与颈动脉狭窄率折线图',
                    left: 'center',
                    top: 16
                },
                xAxis: {
                    type: 'value',
                    splitLine: {
                        lineStyle: {
                            type: 'dashed'
                        }
                    },
                    splitNumber: 20
                },
                yAxis: {
                    type: 'value',
                    min: 0,
                    splitLine: {
                        lineStyle: {
                            type: 'dashed'
                        }
                    }
                },
                grid: {
                    top: 90
                },
                series: [{
                    name: '喝酒指数与颈动脉狭窄率',
                    type: 'scatter',
                    label: {
                        emphasis: {
                            show: true,
                            position: 'right',
                            textStyle: {
                                color: 'blue',
                                fontSize: 16
                            }
                        }
                    },
                    data: jdmxzl
                }, {
                    name: 'line',
                    type: 'line',
                    smooth: true,
                    showSymbol: false,
                    data: myRegression.points,
                    markPoint: {
                        itemStyle: {
                            normal: {
                                color: 'transparent'
                            }
                        },
                        label: {
                            normal: {
                                show: true,
                                position: 'left',
                                formatter: myRegression.expression,
                                textStyle: {
                                    color: '#333',
                                    fontSize: 14
                                }
                            }
                        },
                        data: [{
                            coord: myRegression.points[myRegression.points.length - 1]
                        }]
                    }
                }]
            };
            myChart2.setOption(option2);

            var dom3 = document.getElementById("container3");
            var myChart3 = echarts.init(dom3);
            var myRegression3 = ecStat.regression('polynomial', bmi, 3);
            myRegression3.points.sort(function(a, b) {
                return a[0] - b[0];
            });
            option3 = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross'
                    }
                },
                title: {
                    text: '喝酒指数与BMI关系',
                    left: 'center',
                    top: 16
                },
                xAxis: {
                    type: 'value',
                    splitLine: {
                        lineStyle: {
                            type: 'dashed'
                        }
                    },
                    splitNumber: 20
                },
                yAxis: {
                    type: 'value',
                    min: 0,
                    splitLine: {
                        lineStyle: {
                            type: 'dashed'
                        }
                    }
                },
                grid: {
                    top: 90
                },
                series: [{
                    name: '喝酒指数与BMI',
                    type: 'scatter',
                    label: {
                        emphasis: {
                            show: true,
                            position: 'right',
                            textStyle: {
                                color: 'blue',
                                fontSize: 16
                            }
                        }
                    },
                    data: bmi
                }, {
                    name: 'line',
                    type: 'line',
                    smooth: true,
                    showSymbol: false,
                    data: myRegression.points,
                    markPoint: {
                        itemStyle: {
                            normal: {
                                color: 'transparent'
                            }
                        },
                        label: {
                            normal: {
                                show: true,
                                position: 'left',
                                formatter: myRegression.expression,
                                textStyle: {
                                    color: '#333',
                                    fontSize: 14
                                }
                            }
                        },
                        data: [{
                            coord: myRegression.points[myRegression.points.length - 1]
                        }]
                    }
                }]
            };
            myChart3.setOption(option3);


            var dom4 = document.getElementById("container4");
            var myChart4 = echarts.init(dom4);
            var option4 = {
                title:{
                    text:'喝酒情况统计'
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "喝酒情况统计 <br/>{b} : {d}%"
                },
                series:[{
                    type:'pie',
                    radius:'60%',
                    data:[
                        {value:drink[0],name:'<250ml'},
                        {value:drink[1],name:'250ml-500ml'},
                        {value:drink[2],name:'500ml-750ml'},
                        {value:drink[3],name:'750ml-1000ml'},
                        {value:drink[4],name:'>1000ml'}
                    ]
                }]
            };
            myChart4.setOption(option4);
        }
    });
}

alltypepageing("/Auth/check/findByPage.shtml",null);
